package org.rexsong.sample.petstore.controllers;

import org.rexsong.sample.petstore.exceptions.PetStoreException;
import org.rexsong.sample.petstore.models.Customer;
import org.rexsong.sample.petstore.models.Invoice;
import org.rexsong.sample.petstore.models.Order;
import org.rexsong.sample.petstore.models.Pet;
import org.rexsong.sample.petstore.repositories.CustomerRepository;
import org.rexsong.sample.petstore.repositories.InvoiceRepository;
import org.rexsong.sample.petstore.repositories.OrderRepository;
import org.rexsong.sample.petstore.services.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class OrderController {
    private OrderService orderService;

    @Autowired
    public OrderController(OrderService orderService){
        this.orderService = orderService;
    }

    @RequestMapping(path= "/order/add/{petId}/{customerId}", method = RequestMethod.GET)
    public void add(@PathVariable("petId") final long petId, @PathVariable("customerId") final long customerId) throws PetStoreException {
        orderService.createOrder(petId, customerId);
    }

    @RequestMapping(path= "/orders/{price}", method = RequestMethod.GET)
    public List<Order> orders(@PathVariable("price") final double price) throws PetStoreException {
        return orderService.getOrdersPriceAbove(price);
    }
}
